home *** CD-ROM | disk | FTP | other *** search
/ Clickx 63 / Clickx 63.iso / software / multimedia / mirov204 / Miro_Installer.exe / xulrunner / chrome / toolkit.jar / content / global / globalOverlay.js < prev    next >
Encoding:
Text File  |  2008-03-13  |  5.7 KB  |  204 lines

  1. function closeWindow(aClose, aPromptFunction)
  2. {
  3.   var windowCount = 0;
  4.   var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  5.                      .getService(Components.interfaces.nsIWindowMediator);
  6.   var e = wm.getEnumerator(null);
  7.   
  8.   while (e.hasMoreElements()) {
  9.     var w = e.getNext();
  10.     if (++windowCount == 2) 
  11.       break;
  12.   }
  13.  
  14. //@line 16 "/e/xr19rel/WINNT_5.2_Depend/mozilla/toolkit/content/globalOverlay.js"
  15.   // If we're down to the last window and someone tries to shut down, check to make sure we can!
  16.   if (windowCount == 1 && !canQuitApplication())
  17.     return false;
  18.   else if (windowCount != 1)
  19. //@line 21 "/e/xr19rel/WINNT_5.2_Depend/mozilla/toolkit/content/globalOverlay.js"
  20.     if (typeof(aPromptFunction) == "function" && !aPromptFunction())
  21.       return false;
  22.  
  23.   if (aClose)    
  24.     window.close();
  25.   
  26.   return true;
  27. }
  28.  
  29. function canQuitApplication()
  30. {
  31.   var os = Components.classes["@mozilla.org/observer-service;1"]
  32.                      .getService(Components.interfaces.nsIObserverService);
  33.   if (!os) return true;
  34.   
  35.   try {
  36.     var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
  37.                               .createInstance(Components.interfaces.nsISupportsPRBool);
  38.     os.notifyObservers(cancelQuit, "quit-application-requested", null);
  39.     
  40.     // Something aborted the quit process. 
  41.     if (cancelQuit.data)
  42.       return false;
  43.   }
  44.   catch (ex) { }
  45.   return true;
  46. }
  47.  
  48. function goQuitApplication()
  49. {
  50.   if (!canQuitApplication())
  51.     return false;
  52.  
  53.   var appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1'].
  54.                      getService(Components.interfaces.nsIAppStartup);
  55.  
  56.   appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit);
  57.   return true;
  58. }
  59.  
  60. //
  61. // Command Updater functions
  62. //
  63. function goUpdateCommand(aCommand)
  64. {
  65.   try {
  66.     var controller = top.document.commandDispatcher
  67.                         .getControllerForCommand(aCommand);
  68.  
  69.     var enabled = false;
  70.     if (controller)
  71.       enabled = controller.isCommandEnabled(aCommand);
  72.  
  73.     goSetCommandEnabled(aCommand, enabled);
  74.   }
  75.   catch (e) {
  76.     dump("An error occurred updating the " + aCommand + " command\n");
  77.   }
  78. }
  79.  
  80. function goDoCommand(aCommand)
  81. {
  82.   try {
  83.     var controller = top.document.commandDispatcher
  84.                         .getControllerForCommand(aCommand);
  85.     if (controller && controller.isCommandEnabled(aCommand))
  86.       controller.doCommand(aCommand);
  87.   }
  88.   catch (e) {
  89.     dump("An error occurred executing the " + aCommand + " command\n" + e + "\n");
  90.   }
  91. }
  92.  
  93.  
  94. function goSetCommandEnabled(aID, aEnabled)
  95. {
  96.   var node = document.getElementById(aID);
  97.  
  98.   if (node) {
  99.     if (aEnabled)
  100.       node.removeAttribute("disabled");
  101.     else
  102.       node.setAttribute("disabled", "true");
  103.   }
  104. }
  105.  
  106. function goSetMenuValue(aCommand, aLabelAttribute)
  107. {
  108.   var commandNode = top.document.getElementById(aCommand);
  109.   if (commandNode) {
  110.     var label = commandNode.getAttribute(aLabelAttribute);
  111.     if (label)
  112.       commandNode.setAttribute("label", label);
  113.   }
  114. }
  115.  
  116. function goSetAccessKey(aCommand, aValueAttribute)
  117. {
  118.   var commandNode = top.document.getElementById(aCommand);
  119.   if (commandNode) {
  120.     var value = commandNode.getAttribute(aValueAttribute);
  121.     if (value)
  122.       commandNode.setAttribute("accesskey", value);
  123.   }
  124. }
  125.  
  126. // this function is used to inform all the controllers attached to a node that an event has occurred
  127. // (e.g. the tree controllers need to be informed of blur events so that they can change some of the
  128. // menu items back to their default values)
  129. function goOnEvent(aNode, aEvent)
  130. {
  131.   var numControllers = aNode.controllers.getControllerCount();
  132.   var controller;
  133.  
  134.   for (var controllerIndex = 0; controllerIndex < numControllers; controllerIndex++) {
  135.     controller = aNode.controllers.getControllerAt(controllerIndex);
  136.     if (controller)
  137.       controller.onEvent(aEvent);
  138.   }
  139. }
  140.  
  141. function visitLink(aEvent) {
  142.   var node = aEvent.target;
  143.   while (node.nodeType != Node.ELEMENT_NODE)
  144.     node = node.parentNode;
  145.   var url = node.getAttribute("link");
  146.   if (!url)
  147.     return;
  148.  
  149.   var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
  150.                               .getService(Components.interfaces.nsIExternalProtocolService);
  151.   var ioService = Components.classes["@mozilla.org/network/io-service;1"]
  152.                             .getService(Components.interfaces.nsIIOService);
  153.   var uri = ioService.newURI(url, null, null);
  154.  
  155.   // if the scheme is not an exposed protocol, then opening this link
  156.   // should be deferred to the system's external protocol handler
  157.   if (protocolSvc.isExposedProtocol(uri.scheme)) {
  158.     var win = window.top;
  159.     if (win instanceof Components.interfaces.nsIDOMChromeWindow) {
  160.       while (win.opener && !win.opener.closed)
  161.         win = win.opener;
  162.     }
  163.     win.open(uri.spec);
  164.   }
  165.   else
  166.     protocolSvc.loadUrl(uri);
  167. }
  168.  
  169. function isValidLeftClick(aEvent, aName)
  170. {
  171.   return (aEvent.button == 0 && aEvent.originalTarget.localName == aName);
  172. }
  173.  
  174. function setTooltipText(aID, aTooltipText)
  175. {
  176.   var element = document.getElementById(aID);
  177.   if (element)
  178.     element.setAttribute("tooltiptext", aTooltipText);
  179. }
  180.  
  181. function FillInTooltip ( tipElement )
  182. {
  183.   var retVal = false;
  184.   var textNode = document.getElementById("TOOLTIP-tooltipText");
  185.   if (textNode) {
  186.     while (textNode.hasChildNodes())
  187.       textNode.removeChild(textNode.firstChild);
  188.     var tipText = tipElement.getAttribute("tooltiptext");
  189.     if (tipText) {
  190.       var node = document.createTextNode(tipText);
  191.       textNode.appendChild(node);
  192.       retVal = true;
  193.     }
  194.   }
  195.   return retVal;
  196. }
  197.  
  198. __defineGetter__("NS_ASSERT", function() {
  199.   delete this.NS_ASSERT;
  200.   var tmpScope = {};
  201.   Components.utils.import("resource://gre/modules/debug.js", tmpScope);
  202.   return this.NS_ASSERT = tmpScope.NS_ASSERT;
  203. });
  204.